﻿//作者：MrLee
//时间：2011-9-15
//名称：住户管理
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.HousePersonAddGrid = function (config) {
    Ext.apply(this, config);
    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/HousePersonAddService.aspx?Action=Search'

        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Number', 'Owner', 'Leader', 'Purpose', 'HouseDistrict', 'CreateDate', 'ModifyDate']
        }),
        remoteStore: true
    });
    this.store = fileStore;

    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        noSort: true,
        defaultNum: 21
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();

    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    }, {
        header: '所属小区院落',
        dataIndex: 'HouseDistrict',
        sortable: true,
        width:180
    }, {
        header: '门牌号',
        dataIndex: 'Number',
        sortable: true,
        width: 180
    }, {
        header: '用途',
        dataIndex: 'Purpose',
        sortable: true
    }, {
        header: '房东',
        dataIndex: 'Owner',
        sortable: true
    }, {
        header: '承租人',
        dataIndex: 'Leader',
        sortable: true
    },  {
        header: '创建时间',
        dataIndex: 'CreateDate',
        hidden:true,
        sortable: true
    }, {
        header: '修改时间',
        dataIndex: 'ModifyDate',
        hidden: true,
        sortable: true
    }
    ]

    FantastPlatform.UI.HousePersonAddGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
};
Ext.extend(FantastPlatform.UI.HousePersonAddGrid, Ext.grid.GridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.HousePersonAddGrid.superclass.onRender.call(this, ct, position);
    },
    //添加
    onAddHousePersonAddGridClick: function () {
        var id = GUID();
        currtWind = openWind('../InfoCollection/HousePersonAddForm.aspx', id, '新增住户信息', 480, 185, 'new_tab')
    },

    //修改
    onEditHousePersonAddGridClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
                var fId = node[0].get('Id');
                var id = GUID();
                currtWind = openWind('../InfoCollection/HousePersonAddForm.aspx?Id=' + fId, id, '编辑内容', 480, 185, null);
            }
        }
    },
    //人员信息查看
    onPersonCheckClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
                var fId = node[0].get('Id');
                var id = GUID();
                currtWind = openWind('../InfoCollection/HousePersonAddPanel.aspx?id=' + fId, id, '编辑人员信息', 680, 410, null);
            }
        }
    },
    //查看现住人员
    onPersonNowCheckClick: function () {
        this.store.removeAll();
        this.store.proxy.conn = { method: 'post', url: '../Service/HousePersonAddService.aspx?Action=Search' };
        this.store.load({ params: { start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: ''} });
    },
    //查看历史住迹
    onPersonHistryCheckClick: function () {
        this.store.removeAll();
        this.store.proxy.conn = { method: 'post', url: '../Service/HousePersonAddService.aspx?Action=SearchHistory' };
        this.store.load({ params: { start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: ''} });
    },
    //删除
    onDeleteHousePersonAddGridClick: function () {
        var grid = this;
        var node = checkGridSelected(this);
        if (node) {
            Ext.Msg.confirm('提示', '确认要删除选中的数据吗？', function (btn) {
                if (btn == 'yes') {
                    Ext.Msg.wait('正在删除数据，请稍候……', '删除数据');
                    var fIds = getIdFromGrid(node, 'Id');
                    ajaxCalled(null, '../Service/HousePersonAddService.aspx?Action=Delete', fIds, grid, null);
                }

            })
        }
    },
    //查询
    onSearchClick: function () {
        var id = GUID();
        currtWind = openWind('../InfoCollection/HousePersonAddSearchForm.aspx', id, '查询', 360, 150, 'new_tab');
    },
    //刷新
    onUpdataHousePersonAddGridClick: function () {
        this.store.removeAll();
        this.store.proxy.conn = { method: 'post', url: this.url };
        this.store.load({ params: { start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: ''} });
    }
});